﻿function BigNumber(number) {
    this.number = number.split("").reverse();

    this.Add = function (number2) {
        var self = this;

        var newNumber = new Array();

        var b = "";

        if (number2 instanceof BigNumber) {
            b = number2.number.split("").reverse().join("");
        } else {
            b = number2.split("").reverse().join("");
        }
        
        var extra = 0;

        for (var i = 0; i < self.number.length || i < b.length || extra != 0; i++) {
            var data = (parseInt(self.number[i]) || 0) + (parseInt(b[i]) || 0) + extra;

            newNumber[i] = data % 10;

            extra = Math.floor(data / 10);

        }

        self.number = newNumber;
    };

    this.ToString = function () {
        var self = this;

        return self.number.reverse().join("");
    };
}


module.exports = BigNumber;